package com.lml.jdk8.localdate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author luomingliang
 * @date 2021/9/9 21:16
 */
public class SimpleDateFormatUnsafeDemo {

    public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 演示SimpleDateFormat不安全
     */
    public static void main(String[] args) {
        //循环10次，创建10个线程对象并启动
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                try {
                    synchronized (SIMPLE_DATE_FORMAT) {
                        Date date = SIMPLE_DATE_FORMAT.parse("2018-12-12 12:12:12");
                        System.out.println(date);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
